/**
 * Created by admin1 on 2016-10-24.
 */
let request = require('request');
let cheerio = require('cheerio');
const env = process.env.NODE_ENV || 'development';
const config = require('./../config/config.json')[env];
const debug = require('debug')('debug');
const claaaList = require('./demo');
const models = require('../models');
const SENDURl = 'https://cnodejs.org';

return new Promise((resolve, reject)=> {
  request(encodeURI(SENDURl), function (err, res) {
    if (err)
      reject(err);
    else
      resolve(res);
  });
}).then(function (res) {
  //根据网页内容创建DOM操作对象
  let $ = cheerio.load(res.body.toString());
  //解析DOM
  let classList = [];
  $('#topic_list .topic_title').each(function () {
    var $ly = $(this);
    classList.push({
      title: $ly.attr('title'),
      href: $ly.attr('href')
    });
  });
  console.log(classList);
});
